package org.sny7.openOfflineList.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;

import org.sny7.openOfflineList.util.ConfigureManager;

public class Splash extends JFrame {

	private static final long serialVersionUID = 1L;
	
	private static Splash splash;
	
	private Splash() {
		initGUI();
	}
	
	private void initGUI() {
		this.setTitle("Open OfflineList");
		this.getContentPane().setLayout(new BorderLayout());
		
		this.setSize(300, 60);
		
		this.setAlwaysOnTop(true);
		
		this.addWindowListener(new WindowAdapter() {
			public void windowOpened(WindowEvent e) {
				new Thread() {
					public void run() {
						ConfigureManager.loadConfigure();

						MainFrame.display();
					}
				}.start();
			}
		});
		
		JProgressBar progressBar = new JProgressBar(
				JProgressBar.HORIZONTAL, 0, 100);
		progressBar.setIndeterminate(true);
		progressBar.setStringPainted(true);
		progressBar.setString("Loading...");
		this.add(progressBar);
	}
	
	public static void display() {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				splash = new Splash();
				splash.setLocationRelativeTo(null);
				splash.setVisible(true);
			}
		});
	}
	
	public static void close() {
		MainFrame.setEnabled2(true);
		splash.setVisible(false);
	}
	
	public static void setLocationRelativeTo2(Component c) {
		splash.setLocationRelativeTo(c);
		MainFrame.setEnabled2(false);
	}

}
